package com.zhouqinuan.spring.cloud.develop.framework.demo.kafka.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zhouqinuan.spring.cloud.develop.framework.demo.kafka.message.topic.KafkaTopic;
import com.zhouqinuan.spring.cloud.develop.framework.demo.kafka.service.UserService;

import io.swagger.annotations.Api;

@Api(tags = "kafka测试例子")
@RestController
public class KafkaController {

    @Autowired
    private KafkaTemplate<Object, Object> kafkaTemplate;

    @Autowired
    private UserService userService;

    @GetMapping(path = "/send/user")
    public String sendUser(@RequestParam Long uid) {

        kafkaTemplate.send(KafkaTopic.UserInfo.name, userService.getUserInfo(uid));

        return "ok";
    }
}
